package logic.SysRoleMember

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.authorization.domain.SysRoleMember
import cn.ibizlab.core.authorization.service.SysRoleMemberService
import cn.ibizlab.core.authorization.domain.SysRoleMember
import cn.ibizlab.core.authorization.service.SysRoleMemberService
import cn.ibizlab.core.authorization.domain.SysRoleMember
import cn.ibizlab.core.authorization.service.SysRoleMemberService
import cn.ibizlab.core.ad.domain.SysOrganization
import cn.ibizlab.core.ad.service.SysOrganizationService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  系统角色成员
 */
class Member {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    def _filter = new EntityBase()
    //filterMemer
    def _filtermemer = new SysRoleMember()
    //list
    def _list = new SysRoleMember()
    //org
    def _org = new SysOrganization()
    def _realid = new EntityBase()
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        
        
        
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //id 为空
        if(((RuleUtils.test(_default.get('id'), 'ISNULL', 'null')))) {
            throwexception1()
        }
        //orgid not null
        if(((RuleUtils.test(_default.get('organization_id'), 'ISNOTNULL', 'null')))) {
            prepareparam1()
        }
        //orgid为空
        if(((RuleUtils.test(_default.get('organization_id'), 'ISNULL', 'null')))) {
            prepareparam3()
        }
    }

    //准备参数
    def prepareparam1() {
        _org.set("id", _default.get("organization_id"))

        if(true) {
            deaction1()
        }
    }

    //实体行为
    def deaction1() {
        SpringContextHolder.getBean(SysOrganizationService.class).findOrganizationId(_org)

        if(true) {
            prepareparam2()
        }
    }

    //准备参数
    def prepareparam2() {
        _default.set("organization_id", _realid.get(""))

        if(true) {
            prepareparam3()
        }
    }

    //准备参数
    def prepareparam3() {
        _filtermemer.set("n_organization_id_eq", _default.get("organization_id"))
        _filtermemer.set("n_department_id_eq", _default.get("department_id"))
        _filtermemer.set("n_member_group_id_eq", _default.get("member_group_id"))
        _filtermemer.set("n_member_name_like", _default.get("member_name"))
        _filtermemer.set("n_member_uid_eq", _default.get("member_uid"))
        _filtermemer.set("role_id", _default.get("role_id"))
        _filtermemer.set("size", "10000")

        if(true) {
            dedataquery1()
        }
    }

    //抛出异常
    def throwexception1() {
        throw new RuntimeException('处理逻辑执行异常！')
        if(true) {
            end1()
        }
    }

    //实体数据查询
    def dedataquery1() {
        //DEDataQuery 暂未实现
        if(true) {
            end1()
        }
    }

    //结束
    def end1() {

    }

}
